public class Demo2 {
    public static void main(String[] args) {
        long begin = 2022;
        long end = 2022222022;

//        System.out.println(method(123343321));

        int count = 0;
        for (long i = begin; i <= end; i++) {
            if (method(i)) {
//                System.out.println(i);
//                System.out.println(i);
                count++;
            }
        }

        System.out.println(count);
    }

    public static boolean method(long num) {
        String str = num + "";
//        System.out.println(str);
        char[] ch = str.toCharArray();

        if (ch.length == 1) {
            return true;
        } else if (ch.length == 2) {
            return ch[0] == ch[1];
        }

        int left = 0, right = ch.length - 1;
        if (ch[left] != ch[right]) {
            return false;
        }

        left++;
        right--;

        while (left < right) {
            if (ch[left] == ch[right] && ch[left - 1] <= ch[left] && ch[right + 1] <= ch[right]) {
                left++;
                right--;
            } else {
                return false;
            }
        }

        if (left == right) {
            return ch[left] >= ch[left - 1];
        }

        return true;
    }
}
